#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

class Solution {
public:
    int totalFruit(vector<int>& fruits) {
        int left = 0, right = 0;
        int len = 0;
        unordered_map<int, int> hash;
        while (right < fruits.size())
        {
            hash[fruits[right]]++;
            while (hash.size() > 2)
            {
                hash[fruits[left]]--;
                if (hash[fruits[left]] == 0)
                    hash.erase(fruits[left]);
                left++;
            }
            len = max(len, right - left + 1);
            right++;
        }

        return len;
    }
};

int main()
{

	return 0;
}